package com.preguicoso.client.busca;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.InlineHyperlink;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.preguicoso.client.RegistroToken;
import com.preguicoso.shared.entities.EstabelecimentoBean;
import com.preguicoso.shared.entities.PedidoBean;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.ClickEvent;

public class ListaEstabelecimentoItem extends Composite {

	private static ListaEstabelecimentoItemUiBinder uiBinder = GWT
			.create(ListaEstabelecimentoItemUiBinder.class);

	interface ListaEstabelecimentoItemUiBinder extends
			UiBinder<Widget, ListaEstabelecimentoItem> {
	}

	@UiField
	Label nome;
	@UiField
	Label descricao;
	@UiField
	Label endereco;
	@UiField
	InlineHyperlink link;
	@UiField
	Image logo;
	@UiField InlineLabel enderecoImg;
	@UiField InlineLabel descricaoImg;

	public ListaEstabelecimentoItem() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	public ListaEstabelecimentoItem(String nome, String descricao,
			String endereco) {
		initWidget(uiBinder.createAndBindUi(this));
		this.nome.setText(nome);
		this.endereco.setText(endereco);
		this.descricao.setText(descricao);
	}

	public ListaEstabelecimentoItem(EstabelecimentoBean e) {
		initWidget(uiBinder.createAndBindUi(this));
		this.nome.setText(e.getNome());
		this.descricao.setText(e.getDescricao());
		this.endereco.setText(e.getEndereco());
		
		this.link.setText("Delivery " + e.getStatus());
		this.link.setTargetHistoryToken("Estabelecimento/" + e.getId());

		this.descricao.setText(e.getRazaoSocial());
		this.logo.setUrl(e.getLogoURL());
		descricao.setVisible(false);
		endereco.setVisible(false);
	}
	
	@UiHandler("descricaoImg")
	void onDescricaoImgClick(ClickEvent event) {
		if(!descricao.isVisible()){
			descricao.setVisible(true);		
			Timer t = new Timer() {

				@Override
				public void run() {
					descricao.setVisible(false);
				}
			};
			t.schedule(6000);
		}
		else
			descricao.setVisible(false);
	}
	
	@UiHandler("enderecoImg")
	void onEnderecoImgClick(ClickEvent event) {
		if(!endereco.isVisible()){
			endereco.setVisible(true);
			Timer t = new Timer() {
	
				@Override
				public void run() {
					endereco.setVisible(false);
				}
			};
			t.schedule(6000);
		}else
			endereco.setVisible(false);
	}
}
